package com.sgb.kjwl.view.ui.adapter.shopping;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.view.ui.activity.PhotoViewActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.io.Serializable;
import java.util.List;

public class ShopCompanyImgAdapter extends BaseRecycleAdapter<String> {
    private Intent intent;
    private ImageView imageView;
    private RequestOptions options;
    public ShopCompanyImgAdapter(Context context, List<String> datas) {
        super(context, R.layout.item_shop_company_img_list, datas);
         options = new RequestOptions()
                .placeholder(R.drawable.null_img_list)
         .error(R.drawable.null_img_list);//图片加载出来前，显示的图片
    }

    @Override
    public void convert(ItemViewHolder holder, String s) {
        holder.setBinding(BR.viewModel, s);
        imageView = holder.itemView.findViewById(R.id.img_view);
        Glide.with(context).load(s).apply(options).into((imageView));
        imageView.setOnClickListener(view -> openPhotoView(holder.getAdapterPosition()));
    }
    /**
     * 预览
     **/
    private void openPhotoView(int position) {
        if (intent == null) {
            intent = new Intent();
        }
        intent.setClass(context, PhotoViewActivity.class);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) datas);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, position);
        context.startActivity(intent);
    }
}
